package com.example.juc;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CountDownLatchDemo {
	public static void main(String[] args) throws Exception {
		CountDownLatch countDownLatch = new CountDownLatch(5);
		for (int i = 1; i < 6; i++) {
			new Thread(() -> {
				try {
					TimeUnit.SECONDS.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				System.out.println(Thread.currentThread().getName() + "完成任务");
				countDownLatch.countDown();
			}, String.valueOf(i)).start();
		}
		
		countDownLatch.await();
		System.out.println(Thread.currentThread().getName() + "关闭任务");
	}
}
